package fatworm.query;

import fatworm.storage.table.*;
import fatworm.query.constant.Constant;

public class SelectScan implements UpdateScan {
	
	private Scan s;
	private Predicate pred;
	
	public SelectScan(Scan s, Predicate pred) {
		this.s = s;
		this.pred = pred;
	}
	
	public void beforeFirst() {
		s.beforeFirst();
	}
	
	public boolean next() {
		while (s.next()) 
			if (pred.isOK(s))
				return true;
			
		return false;
	}
	
	public void close() {
		s.close();
	}
	
	public Constant getVal(String name) {
		return s.getVal(name);
	}
	
/*	public int getInt(String name) {
		return s.getInt(name);
	}
	
	public String getString(String name) {
		return s.getString(name);
	}*/
	
	public boolean hasField(String name) {
		return s.hasField(name);
	}
	
	public void setVal(String name, Constant val) {
		UpdateScan us = (UpdateScan)s;
		us.setVal(name, val);
	}
	
/*	public void setInt(String name, int val) {
		UpdateScan us = (UpdateScan)s;
		us.setInt(name, val);
	}
	
	public void setString(String name, String val) {
		UpdateScan us = (UpdateScan)s;
		us.setString(name, val);
	}*/
	
	public void insert() {
		UpdateScan us = (UpdateScan)s;
		us.insert();
	}
	
	public void delete() {
		UpdateScan us = (UpdateScan)s;
		us.delete();
	}
	
	public RID getRID() {
		UpdateScan us = (UpdateScan)s;
		return us.getRID();
	}
	
	public void moveToRID(RID rid) {
		UpdateScan us = (UpdateScan)s;
		us.moveToRID(rid);
	}
}